<html>
<head><meta charset="utf-8"><title>Lint suggestions needing imports · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lint.20suggestions.20needing.20imports.html">Lint suggestions needing imports</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="247128366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lint%20suggestions%20needing%20imports/near/247128366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Wagner-Hall <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lint.20suggestions.20needing.20imports.html#247128366">(Jul 25 2021 at 14:12)</a>:</h4>
<p>Is there a way for a Lint autofix suggestion to also suggest that a <code>use</code> will need to be added to the file? I have a lint which wants to suggest using a method from a trait, but if the trait doesn't happen to be <code>use</code>d, applying the fix would break the code...</p>
<p>I could suggest <code>&lt;foo as ::fully::qualified::Trait&gt;::bar()</code> but that seems like it's much less user-friendly.</p>



<a name="247129328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lint%20suggestions%20needing%20imports/near/247129328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lint.20suggestions.20needing.20imports.html#247129328">(Jul 25 2021 at 14:41)</a>:</h4>
<p>I know <code>multipart_suggestion</code> is a thing, but it could be difficult to find the span where the <code>use</code> needs to be added - maybe downgrade it from <code>MachineApplicable</code> instead of changing the suggestion?</p>



<a name="247129333"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lint%20suggestions%20needing%20imports/near/247129333" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lint.20suggestions.20needing.20imports.html#247129333">(Jul 25 2021 at 14:41)</a>:</h4>
<p>you could also have two versions, one which is tool-only and uses <code>::fully::qualified</code> and the other which uses the short name</p>



<a name="247129459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lint%20suggestions%20needing%20imports/near/247129459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lint.20suggestions.20needing.20imports.html#247129459">(Jul 25 2021 at 14:45)</a>:</h4>
<p>In regards to finding the span, there are two implementations of <code>UsePlacementFinder</code>. They mostly work, but are somewhat buggy.</p>



<a name="247129835"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lint%20suggestions%20needing%20imports/near/247129835" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> The 8472 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lint.20suggestions.20needing.20imports.html#247129835">(Jul 25 2021 at 14:56)</a>:</h4>
<p>can't the fully qualified version be cleaned up in a separate step?</p>



<a name="247130465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Lint%20suggestions%20needing%20imports/near/247130465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Daniel Wagner-Hall <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Lint.20suggestions.20needing.20imports.html#247130465">(Jul 25 2021 at 15:08)</a>:</h4>
<p>Is there an automated cleaning up there? Like, if <code>rustfmt</code> will notice the conversion is redundant and remove it, or something, that would be grand, but that seems hard...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>